<template>
  <div>
    <el-form ref="" :model="formFileds">
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item>
            <el-input></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item>
            <el-button type="primary">
              查询
            </el-button>
            <el-button type="primary">
              清空
            </el-button>
            <el-button type="primary" @click="add()">
              添加
            </el-button>
            <el-button type="danger" @click="deleteAll()">
              批量删除
            </el-button>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>

    <!--表格内容-->
    <el-table
      ref="auctioneerForm"
      :data="tableData"
      style="width: 100%; margin-bottom: 5px"
      border
      stripe
      :header-cell-style="{textAlign:'center'}"
      :cell-style="{textAlign:'center'}"
      highlight-current-row
      @row-click="handleRowClick"
      @select-all="handleCheckedAllAndCheckedNone"
      @select="handleCheckedAllAndCheckedNone"
    >
      <el-table-column type="selection" fixed="left">
      </el-table-column>
      <!-- <el-table-column property="id" label="id">
      </el-table-column> -->
      <el-table-column property="pmsbh" label="拍卖师编号" >
      </el-table-column>
      <el-table-column property="pmsxm" label="拍卖师姓名" >
      </el-table-column>
      <el-table-column property="pmszsbh" label="拍卖师证书编号" >
      </el-table-column>
      <el-table-column  label="拍卖师证书照">
        <template slot-scope="scope">
          <img :src="scope.row.pmszsz" style="width: 120px; height: 100px;">
        </template>
      </el-table-column>

      <el-table-column label="操作" width="150" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button circle icon="el-icon-upload2" title="上传证书照片" type="success" size="small" @click="upload()"></el-button> -->
          <!-- <el-button
            type="primary"
            title="编辑"
            size="mini"
            @click="rowEdit(scope.row)"
          >编辑</el-button>
          <el-button
            type="danger"
            title="删除"
            size="mini"
            @click="rowDel(scope.row, $event)"
          >删除</el-button> -->
          <el-dropdown>
            <el-button type="primary">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @command="rowEdit(scope.row)">编辑</el-dropdown-item>
              <el-dropdown-item @command="rowDel(scope.row, $event)">删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>


    </el-table>
    <!--分页-->
    <el-pagination :page-sizes="[10, 20, 30, 40, 100]" :page-size=this.pageSize :total=this.total :current-page="currentPage" 
    layout="total, sizes, prev, pager, next, jumper" @current-change="getCurrentPage" @size-change="getSize">
    </el-pagination>
    <Edit v-if="isShowEditDialog" :isShowEditDialog="isShowEditDialog"
      @dialogClose="dialogClose"
      :rowData="rowData"></Edit>
    <Add v-if="isShowAddDialog" :isShowAddDialog="isShowAddDialog"  @dialogClose="dialogClose"></Add>
  </div>
</template>
    
  <script>
  import Edit from "./auctioneerEdit";
  import Add from "./auctioneerAdd";
  import { getAll,delData } from '@/api/auctionManage/auctioneer';
  export default {
  name: "Table",
  components: {
    Edit,
    Add,
  },
  data() {
    return {
      pageSize: 10,
      total: 0,
      currentPage: 1,
      param: '',
      formFileds: {
        text: '',
        param: ''
      },
      tableData: [
        // {
        //   index: 0,
        //   id: 1,
        //   name: '张三',
        //   certificateId: 13234,
        //   certificatePhoto: 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg'
        // },
        // {
        //   index: 1,
        //   id: 2,
        //   name: '李四',
        //   certificateId: 66666,
        //   certificatePhoto: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
        // },
        {
          id: '',
          pmsbh: '',
          pmsxm: '',
          pmszsbh: '',
          pmszsz: ''
        }
      ],
      isShowEditDialog: false,
      isShowAddDialog: false,
      rowData: {},
    };
  },
  methods: {
    handleRowClick(row, event, column) {
      // 仅选中当前行
      this.setCurRowChecked(row);
    },
    handleCheckedAllAndCheckedNone(selection) {
      // 当前选中仅一行时操作-（当前表格行高亮）
      1 != selection.length && this.$refs.auctioneerForm.setCurrentRow();
    },
    dialogClose() {
      this.isShowEditDialog = false;
      this.isShowAddDialog = false;
      this.isShowPhoto = false;
      this.getList();
    },
    add(){
      this.isShowAddDialog = true;
    },
    photo(){
      this.isShowPhoto = true;
    },
    rowEdit(row) {
      // //当前选中行
      this.rowData = row;
      this.isShowEditDialog = true;
    },
    handleEdit(id) {
      this.$refs.auctioneerForm.validate((isValid) => {
        if (!isValid) return;

        // 保存编辑后的数据
        Object.assign(this.tableData[id], this.formFileds);
        this.isShowEditDialog = false;

        // 考虑到可能编辑了日期-需要重新排序
        // ***注意：手动排序传参和表格的default-sort属性格式不太一样
        this.$refs.auctioneerForm.sort("date", "descending");

        this.$message.success("编辑成功");
      });
    },
    rowDel(row, event) {
      // 让当前删除按钮失焦
      event.target.blur();

      this.$confirm("确定要删除当前行吗？", "删除", {
        comfirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(() => {
        delData(row.id).then((res) => {
          console.log(res);
          this.tableData.splice(row.id, 1);
          this.$message.success("删除成功");
          this.getList();
        })
      });
    },
    // 选中当前行-当前行的复选框被勾选
    setCurRowChecked(row) {
      this.$refs.auctioneerForm.clearSelection();
      this.$refs.auctioneerForm.toggleRowSelection(row);
    },
    getCurrentPage(currentPage){
      // console.log(currentPage);
      this.currentPage = currentPage;
      this.getList();
    },
    getSize(pageSize){
      // console.log(pageSize);
      this.pageSize = pageSize;
      this.getList();
    },
    getList(){
      this.param = 'pageno=' + this.currentPage + '&countonepage=' + this.pageSize;
      getAll(this.param).then((res) => {
        if(res){
          console.log(res);
          this.total = res.data.total;
          this.tableData = res.data.list;
          // this.tableData = this.formatData(this.tableData);
        }
      })
    },
  },
  mounted(){
    this.getList();
  }
};
</script>
    
  <style scoped lang="less">
.el-form {
  padding: 0 10px;
}

.el-date-editor {
  width: 100% !important;
}
</style>
    